/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets.admin;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dbconnector.DBDriver;
import java.sql.*;
import AO.*;

/**
 *
 * @author FRIENDS
 */
@WebServlet(name = "showusers", urlPatterns = {"/administrator/view/showusers"})
public class showusers extends HttpServlet {

   
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String user=request.getParameter("user");
        String order=request.getParameter("order");
        
        Login loginbean;
        Faculty faculty=null;
        Student student=null;
        try
        {
        PreparedStatement pstmt=DBDriver.getPrepare("select * from login order by "+order);
        ResultSet rs1=pstmt.executeQuery();
        
        while(rs1.next())
        {
            loginbean=helper.Login.getLoginBean(rs1.getString("userid"),rs1.getString("password"));
            if(loginbean.getType().equals("student"))
                student=helper.Login.getStudentBean(rs1.getString("userid"));
            if(loginbean.getType().equals("faculty"))
                faculty=helper.Login.getFacultyBean(rs1.getString("userid"));        
        if(rs1.getString("usertype").equals("student")&&(user.equals("student")||user.equals("all")))
        {
        out.println("<table  align='left' style='height: 150px;width:70%'>");
        out.println("<caption style='background: #00ff00'>"+loginbean.getUserid()+"[ student ]  joined on "+loginbean.getJoindate()+"</caption>");
        out.println("<tr>");
        out.println("<td style='width:70%'>");
        out.println("first name :"+student.getFname()+"<br />"
                + "last name :"+student.getLname()+"<br />"
                + "qualification :"+student.getQualification()+"<br />"
                + "email :"+student.getEmail()+"<br />"
                + "mobile :"+student.getMobile()+"<br />"
                + "gender :"+student.getGender()+"<br/>"
                + "</td>"
                + "<td style='float: right;width:100%'><a href='showimg?type=student&userid="+student.getUserid()+"' rel='lightbox[roadtrip]'"
                + " title='STUDENT"
                        + "<br>userid: "+student.getUserid()
                        + "<br>First Name: "+student.getFname()
                        +"<br>Last Name : "+student.getLname()
                        +"<br>Qualification: "+student.getQualification()
                        +"<br>email : "+student.getEmail()
                        +"<br>Contact : "+student.getMobile()
                        +"<br>Gender : "+student.getGender()
                        +"'><img src='showimg?type=student&userid="+student.getUserid()+"' style='height: 150px;' /></a>"
                + "</td>");
        out.println("</tr>");
        out.println("</table><br />");
        }
        
        if(rs1.getString("usertype").equals("faculty")&&(user.equals("faculty")||user.equals("all")))
        {
        out.println("<table  align='left' style='height: 150px;width:70%'>");
        out.println("<caption style='background: #ffff00'>"+loginbean.getUserid()+"[ faculty ]  joined on "+loginbean.getJoindate()+"</caption>");
        out.println("<tr>");
        out.println("<td style='width:70%'>");
        out.println("first name : "+faculty.getFname()+"<br />"
                + "last name :: "+faculty.getLname()+"<br />"
                + "qualification : "+faculty.getQualification()+"<br />"
                + "email : "+faculty.getEmail()+"<br />"
                + "mobile : "+faculty.getMobile()+"<br />"
                + "gender : "+faculty.getGender()+"<br/>"
                + "experiance : "+faculty.getExperiance()+"<br />"
                + "salary : "+faculty.getSalary()+"<br />"
                + "</td>"
                + "<td style='float: right;width:100%'><a href='showimg?type=faculty&userid="+faculty.getUserid()+"' rel='lightbox[roadtrip]' "
                + "title='FACULTY<br>"
                + "first name : "+faculty.getFname()+"<br />"
                + "last name :: "+faculty.getLname()+"<br />"
                + "qualification : "+faculty.getQualification()+"<br />"
                + "email : "+faculty.getEmail()+"<br />"
                + "mobile : "+faculty.getMobile()+"<br />"
                + "gender : "+faculty.getGender()+"<br/>"
                + "experiance : "+faculty.getExperiance()+"<br />"
                + "salary : "+faculty.getSalary()+"<br />"
                
                + "'><img src='showimg?type=faculty&userid="+faculty.getUserid()+"' style='height: 150px' /></a>"
                + "</td>");
        out.println("</tr>");
        out.println("</table><br />");
        }
        }
        }
        catch(Exception e){e.printStackTrace();};
        
        }
    
        
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    
    
    @Override
    public String getServletInfo() {
        return "Short description";
    }
}

